package com.ks.user.controller;


import com.ks.core.base._ControllerBase;
import com.ks.core.core.Result;
import com.ks.core.dto.SearchCriteriaBase;
import com.ks.user.controller.dto.ApBaseRequest;
import com.ks.user.entity.ApBase;
import com.ks.user.service.IApBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 应用基本信息表 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-11-30
 */
@RestController
@RequestMapping("/apBase")
@Api(value = "应用服务模块", description = "应用服务模块")
public class ApBaseController extends _ControllerBase {

    @Autowired
    private IApBaseService apBaseService;


    @PostMapping("/getApBaseAdminCount")
    @ApiOperation(value = "应用发布数", notes = "应用发布数")
    public Object getApBaseAdminCount() {
        Map<String, Object> apBaseAdminCount = apBaseService.getApBaseAdminCount(getContext());
        return Result.success(apBaseAdminCount);
    }


    @PostMapping("/getApBaseList")
    @ApiOperation(value = "系统应用模板清单查询接口", notes = "系统应用模板清单查询接口")
    public Object getApBaseList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> apBaseList = apBaseService.getApBaseList(getContext(), searchCriteriaBase);
        return Result.success(apBaseList);
    }

    @PostMapping("/getSysApBaseList")
    @ApiOperation(value = "系统应用应用模板清单查询接口", notes = "系统应用应用模板清单查询接口")
    public Object getSysApBaseList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> apBaseList = apBaseService.getSysApBaseList(getContext(), searchCriteriaBase);
        return Result.success(apBaseList);
    }

    @PostMapping("/addApBase")
    @ApiOperation(value = "应用添加接口", notes = "应用添加接口")
    public Object addApBase(@RequestBody ApBase apBase) {
        int i = apBaseService.addApBase(getContext(), apBase);
        return Result.success(i);
    }

    @PostMapping("/setAppStatus")
    @ApiOperation(value = "应用上线/下线接口", notes = "应用上线/下线接口")
    public Object setAppStatus(@RequestBody ApBaseRequest request) {
        int i = apBaseService.setAppOn(request.getId(), request.getState());
        return Result.success(i);
    }


    @PostMapping("/getApBaseInfo")
    @ApiOperation(value = "应用详情接口", notes = "应用详情接口")
    public Object getApBaseInfo(@RequestBody ApBaseRequest request) {
        ApBase apBaseInfo = apBaseService.getApBaseInfo(request.getId());
        return Result.success(apBaseInfo);
    }

    @PostMapping("/updateApBase")
    @ApiOperation(value = "应用信息修改接口", notes = "应用信息修改接口")
    public Object updateApBase(@RequestBody ApBase apBase) {
        int i = apBaseService.updateApBase(apBase.getId(), apBase.getIAppCode(), apBase.getIAppName(), apBase.getIIcon(), apBase.getIServiceUrlRoot(), apBase.getIPageUrl(), apBase.getCAppScope(), apBase.getCAppType());
        return Result.success(i);
    }

    @PostMapping("/selectTenant")
    @ApiOperation(value = "查询租户授权应用清单接口", notes = "查询租户授权应用清单接口")
    public Object selectTenant() {
        Map<String, Object> resultMap = apBaseService.getTenantList(getContext());
        return Result.success(resultMap);
    }


}

